#include "./cpp-httplib/httplib.h"
#include "searcher.hpp"
#include <iostream>
#include "log.hpp"

const std::string root = "./wwwroot";
const std::string raw = "./data/raw_html/raw.txt";

int main()
{
    httplib::Server svr;
    ns_searcher::searcher sc;
    sc.initSearcher(raw);
    svr.set_base_dir(root.c_str());
    //这里的res不是const
    svr.Get("/s", [&sc](const httplib::Request &req, httplib::Response &rsp)
            {
        if(!req.has_param("word"))
        {
            rsp.set_content("必须要有搜索关键字！","text/plain;charset=utf-8");
        }
            std::string word=req.get_param_value("word");
        std::string msg="searching:";
        msg+=word;
    LOG(NORMAL,msg);

    std::string json;

    sc.search(word,&json);


    rsp.set_content(json,"application/json"); });
    svr.listen("0.0.0.0", 8080);
    return 0;
}
